public class solution1 {
    public static void main(String[] args) {
        int[] nums = {1,3,5,6};
        int target = 7;
        int result = searchInsert(nums, target);
        System.out.println(result);
    }
    public static int searchInsert(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        while(left < right) {
            int mid = left + (right - left) / 2;
            if(nums[mid] < target) {
                left = mid + 1;
            }else {
                right = mid;
            }
        }

        if(nums[right] >= target) {
            return right;
        }else {
            return right + 1;
        }
    }
}
